﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SolutionClone.View;
using SolutionClone.Presenter;

namespace SolutionClone
{
    public partial class Form1 : Form, ISolutionClonerView, IInputValidator
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnSourceDir_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK == folderBrowserDialog1.ShowDialog())
                txtSourceDirectory.Text = folderBrowserDialog1.SelectedPath;
        }

        private void btnDestDir_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK == folderBrowserDialog1.ShowDialog())
                txtDestinationDirectory.Text = folderBrowserDialog1.SelectedPath;
        }

        private void btnConvert_Click(object sender, EventArgs e)
        {
            this.Clone();
        }

        private void ValidControlColor(Control ctrl, bool validValue)
        {
            if (!validValue)
                ctrl.BackColor = System.Drawing.Color.FromKnownColor(KnownColor.Pink);
            else
                ctrl.BackColor = System.Drawing.Color.FromKnownColor(KnownColor.Window);
        }

        #region ISolutionClonerView Members

        public string OldPath
        {
            get { return txtSourceDirectory.Text; }
        }

        public string NewPath
        {
            get { return txtDestinationDirectory.Text; }
        }

        public string OldName
        {
            get { return txtSourceName.Text; }
        }

        public string NewName
        {
            get { return txtDestinationName.Text; }
        }

        public bool Running
        {
            set
            {
                btnConvert.Enabled = !value;
                btnConvert.Refresh();
            }
        }

        #endregion


        #region IInputValidator Members

        public bool OldPathValid
        {
            set { ValidControlColor(txtSourceDirectory, value); }
        }

        public bool NewPathValid
        {
            set { ValidControlColor(txtDestinationDirectory, value); }
        }

        public bool OldNameValid
        {
            set { ValidControlColor(txtSourceName, value); }
        }

        public bool NewNameValid
        {
            set { ValidControlColor(txtDestinationName, value); }
        }

        public string ErrorText
        {
            set { lblStatusBar.Text = value; }
        }

        #endregion

        private void txtSourceDirectory_TextChanged(object sender, EventArgs e)
        {
            this.ValidateOldPath();
        }

        private void txtDestinationDirectory_TextChanged(object sender, EventArgs e)
        {
            this.ValidateNewPath();
        }

        private void txtSourceName_TextChanged(object sender, EventArgs e)
        {
            this.ValidateOldName();
        }

        private void txtDestinationName_TextChanged(object sender, EventArgs e)
        {
            this.ValidateNewName();
        }
    }
}
